/*
	@file : perf/PerfObject.cpp
	@author : Wolfhead
*/
#include "perf/PerfObject.h"
#include "perf/PerfManager.h"
#include "perf/PerfScope.h"
#include <boost/lexical_cast.hpp>

namespace logger
{
namespace perf
{

PerfObject::PerfObject()
{
	m_string = "{";
}

void PerfObject::step_in(
	boost::posix_time::ptime time,
	const std::string message)
{
	//TODO wolfhead: remove hard code
	m_string.reserve(m_string.size() + message.size() + 50/*magic*/);

	m_string.append("\"s\":\"")
	        .append(boost::posix_time::to_iso_string(time))
	        .append("\",\"m\":")
	        .append(message)
	        .append("\",\"f\":{");
}

void PerfObject::step_out(
	boost::posix_time::ptime time,
	boost::posix_time::time_duration laterncy)
{

	m_string.append("}\"e\":\"")
	        .append(boost::posix_time::to_iso_string(time))
	        .append("\",\"l\":")
	        .append(boost::lexical_cast<std::string>(
	        	laterncy.total_microseconds()))
	        .append("\"");
}

std::string PerfObject::get_perf()
{
	return m_string.append("}");
}

}// namespace logger	
}// namespace perf